package p2p;

import java.util.Hashtable;

import catalogo.ArquivoCatalogo;
import catalogo.Catalogo;
import rice.p2p.commonapi.Id;
import rice.p2p.commonapi.Message;
import rice.p2p.commonapi.NodeHandle;

public class SyncMessage implements Message 
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -3664183245872075620L;
	public static final int GET_TIMESTAMP = 0;
	public static final int SEND_CATALOG = 1;
	public static final int GET_FILE = 2;
	public static final int RSP_TIMESTAMP = 3;
	public static final int RSP_FILE = 4;
	
	/**
	 * fields
	 */
	public int typeMessage;
	public String key;
	public int timestamp;
	public Id fromId;
	public NodeHandle source;
	public Hashtable<String,ArquivoCatalogo> catalogo;

	public SyncMessage()
	{
	}
	
	public SyncMessage(int type, String key, NodeHandle source)
	{
		typeMessage = type;
		this.key = key;
		this.source = source;
	}

	public SyncMessage(int type, Catalogo catalogo)
	{
		typeMessage = type;
		this.catalogo = catalogo.getArquivos();
	}

	@Override
	public int getPriority()
	{
		return Message.LOW_PRIORITY;
	}
	
	public String toString()
	{
		String s;
		switch (typeMessage)
		{
		case GET_TIMESTAMP:
			s = "GET_TIMESTAMP";
			break;
		case GET_FILE:
			s = "GET_FILE";
			break;
		case RSP_FILE:
			s = "RSP_FILE";
			break;
		case RSP_TIMESTAMP:
			s = "RSP_TIMESTAMP";
			break;
		case SEND_CATALOG:
			s = "SEND_CATALOG";
			break;
		default: s = "MENSAGEM DESCONHECIDA";
		}
		return s;
	}
}
